package com.novabluetooth.views;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.health.R;
import com.health.db.DbManager;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.NEW_GXB;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;
import com.novabluetooth.views.iknetbluetoothlibrary.AndroidtoJs;

import java.util.List;

public class TestActivity extends NovaActivity {

    private DbManager dbmanger = null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_ac);
        dbmanger = ((NovaApplication) getApplication()).getDbManger();
        dbmanger.addNewTable();
        WebView wv = (WebView) findViewById(R.id.wv);
        WebSettings settings = wv.getSettings();
        Intent intent = getIntent();
        String type = intent.getStringExtra("type");
        // 设置编码格式
        settings.setDefaultTextEncodingName("utf-8");
        // 支持js
        settings.setJavaScriptEnabled(true);//必须得设置不然js代码不能实现
        settings.setJavaScriptCanOpenWindowsAutomatically(true);//允许js弹出窗口
        wv.getSettings().setDomStorageEnabled(true);
        wv.addJavascriptInterface(new AndroidtoJs(TestActivity.this),"app");
        ARCHIVE_BASEINFO userInfo = NovaApplication.getUserInfo();
        String sex = userInfo.getSEX();
        String currentSex = "";
        if(sex.equals("DM01-08_1")){
            currentSex ="男";
        }else {
            currentSex ="女";
        }
        System.out.println(userInfo.getCUSTOMERNAME()+"--"+currentSex+"--"+userInfo.getID());

        switch (type){
            case "1":
                wv.loadUrl("file:///android_asset/page/gxb.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
            case "2":
                wv.loadUrl("file:///android_asset/page/gjy.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
            case "3":
                wv.loadUrl("file:///android_asset/page/lfxgjy.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
            case "4":
                wv.loadUrl("file:///android_asset/page/lnmxzqgy.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
            case "5":
                wv.loadUrl("file:///android_asset/page/mzf.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
            case "6":
                wv.loadUrl("file:///android_asset/page/ybrq.html?name="+userInfo.getCUSTOMERNAME()+"&sex="+currentSex+"&personid="+userInfo.getID()+"");
                break;
        }
        //系统默认会通过手机浏览器打开网页，为了能够直接通过WebView显示网页，则必须设置
        settings.setBuiltInZoomControls(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
//        settings.setSavePassword(true);
//        settings.setSaveFormData(true);
//        settings.setJavaScriptEnabled(true);     // enable navigator.geolocation
        settings.setGeolocationEnabled(true);
        settings.setDomStorageEnabled(true);
        wv.requestFocus();
//        wv.setScrollBarStyle(0);
        wv.setWebChromeClient(new WebChromeClient());
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //使用WebView加载显示url
                view.loadUrl(url);
                //返回true
                return true;
            }
        });
    }

    @Override
    public void findViews() {

    }

    @Override
    public void setListeners() {

    }
}
